// 引入 Mock
import Mock from "mockjs";

// 定义数据类型
let { data } = Mock.mock({

  "data|72": [
    {
      "id|+1": 1,
      'name|min-max': Number,
      'name':/^[A-Z]{2}[0-9]{11}$/,
      "eventName|1": ["萧山区国庆酒驾巡查", "西湖区国庆酒驾巡查"],
      "eventArea|1": ["萧山区古城街道路段", "西湖区转塘街道路段"],
      "team|1": ["侯亮平巡查小队", "李达康巡查小队"],
      "abnormal|1": ["是", "否"],
      "eventType|1": ['普通巡查'],
      "checkTimeStart|2003058804-183058804": 1403058804,
      "checkTimeEnd|2003058804-183058804": 1403058804,
      prosonName: "@cname",
    
    },
  ],
});
// 输出结果随机生成的数据（node index.js）
// console.log(data);

Mock.mock("/api/working", "post", (option) => {
  const {formInline, currentPage, pageSize } = JSON.parse(option.body);
  let result = []
  let count = 0
  console.log(formInline);
  if (true) {
    const filterValueFirst = data.filter((item) => String(item.eventArea).search(formInline.city) != -1);
    const filterValue = filterValueFirst.filter((item) => String(item.prosonName).search(formInline.value) != -1);
    result = filterValue.slice(
      (currentPage - 1) * pageSize,
      currentPage * pageSize
    );
    count = filterValue.length;
  } else {
    result = data.slice((currentPage - 1) * pageSize, currentPage * pageSize);
    count = data.length;
  }
  return {
    result: result,
    status: 0,
    total: data.length,
  };
});

export default Mock;
